define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'neworder/order/index',
                    edit_url: 'neworder/order/edit',
                    del_url: 'neworder/order/del',
                    multi_url: 'neworder/order/multi',
                    table: 'fa_order',
                }
            });


            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'ordersn', title: __('Order number ')},
                        {field: 'user.username', title: __('Username')},
                        {field: 'machine.name', title: __('Machine name')},
                        {field: 'realpay', title: __('Money')},
                        {field: 'fee', title: __('Fee')},
                        {field: 'day', title: __('Set number of days')},
                        {field: 'rate', title: __('Day return rate (%)')},
                        {field: 'bonusstatus', title: __('收益状态'), formatter: Controller.api.formatter.age},
                        {field: 'bonus', title: __('Earned income')},
                        {field: 'createtime', title: __('createtime')},
                        // {field: 'operate', title: __('Operate'), table: table,
                        //     events: Table.api.events.operate,
                        //     formatter: Table.api.formatter.operate}
                    ]
                ]
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter: {
                age: function (value, row, index) {
                    if(value==1){
                        return '<span style="color:green">'+__('Earnings')+'</span>';
                    }else if(value==2){
                        return '<span style="color:#33338f">'+__('Finished')+'</span>';
                    }else{
                        return '<span style="color:red">'+__('Surrender of tenancy')+'</span>';
                    }

                }
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});